/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

/**
 * This class is a JPA entity and represents an administrator
 * as it will be stored in the database
 * 
 * @author Amigos do Noddy
 *
 */
@Entity
@Table(name = "ADMINISTRATOR", schema = "APP")
//@NamedQueries({@NamedQuery(name = "Administrator.findByRefidperson", query = "SELECT a FROM Administrator a WHERE a.refidperson = :refidperson"), @NamedQuery(name = "Administrator.findByLevel", query = "SELECT a FROM Administrator a WHERE a.level = :level")})
@PrimaryKeyJoinColumn(name = "REFIDPERSON", referencedColumnName = "IDPERSON")
@DiscriminatorValue("Administrador")
public class Administrator extends Person implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /*@Id
    @Column(name = "REFIDPERSON", nullable = false)
    private Integer refidperson;*/
    
    @Column(name = "LEVEL", nullable = false)
    private short level;
    @JoinTable(schema = "APP",name = "ADMINISTRATOR_FAQ", joinColumns = {@JoinColumn(name = "REFIDPERSON_ADM", referencedColumnName = "REFIDPERSON")}, inverseJoinColumns = {@JoinColumn(name = "REFIDFAQ", referencedColumnName = "IDFAQ")})
    @ManyToMany
    private Collection<Faq> refidfaqCollection;
    
    /*@JoinColumn(name = "REFIDPERSON", referencedColumnName = "IDPERSON", insertable = false, updatable = false)
    @OneToOne
    private Person person;*/
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "administrator")
    private Collection<Assignment> assignmentCollection;

    /**
     * Default constructor
     */
    public Administrator() {
    }

    /*public Administrator(Integer refidperson) {
        this.refidperson = refidperson;
    }

    public Administrator(Integer refidperson, short level) {
        this.refidperson = refidperson;
        this.level = level;
    }

    public Integer getRefidperson() {
        return refidperson;
    }

    public void setRefidperson(Integer refidperson) {
        this.refidperson = refidperson;
    }*/

    /**
     * Gets the level of administration
     */
    public short getLevel() {
        return level;
    }

    /**
     * Sets the level of administration
     * @param level level of administration
     */
    public void setLevel(short level) {
        this.level = level;
    }

    /**
     * @return id of the list of faqs of this administrator
     */
    public Collection<Faq> getRefidfaqCollection() {
        return refidfaqCollection;
    }

    /**
     * Sets the id of the list of faqs collection of this administrator
     * @param refidfaqCollection id of the list of faqs collection
     */
    public void setRefidfaqCollection(Collection<Faq> refidfaqCollection) {
        this.refidfaqCollection = refidfaqCollection;
    }

    /*public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }*/

    /**
     * Gets the list of assigments by this administrator
     */
    public Collection<Assignment> getAssignmentCollection() {
        return assignmentCollection;
    }

    /**
     * Sets the list of assignments of this administrator
     * @param assignmentCollection list of assignments
     */
    public void setAssignmentCollection(Collection<Assignment> assignmentCollection) {
        this.assignmentCollection = assignmentCollection;
    }

    /*@Override
    public int hashCode() {
        int hash = 0;
        hash += (refidperson != null ? refidperson.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Administrator)) {
            return false;
        }
        Administrator other = (Administrator) object;
        if ((this.refidperson == null && other.refidperson != null) || (this.refidperson != null && !this.refidperson.equals(other.refidperson))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Administrator[refidperson=" + refidperson + "]";
    }*/

}
